import { Form, Input, InputNumber, Select, Switch } from 'antd';
import { Device } from '@/types/device';
import { TimerDTO } from '@/types/timer';
import { FormInstance } from 'antd/lib/form';

interface TimerFormProps {
  form: FormInstance;
  devices: Device[];
  initialValues?: Partial<TimerDTO>;
  onFinish: (values: TimerDTO) => void;
}

const TimerForm: React.FC<TimerFormProps> = ({ form, devices, initialValues, onFinish }) => {
  return (
    <Form
      form={form}
      labelCol={{ span: 6 }}
      wrapperCol={{ span: 16 }}
      initialValues={{ status: true, targetStatus: false, ...initialValues }}
      onFinish={onFinish}
    >
      <Form.Item
        label="任务名称"
        name="name"
        rules={[{ required: true, message: '请输入任务名称' }]}
      >
        <Input placeholder="请输入任务名称" />
      </Form.Item>

      <Form.Item
        label="选择设备"
        name="deviceId"
        rules={[{ required: true, message: '请选择设备' }]}
      >
        <Select placeholder="请选择设备">
          {devices.map(device => (
            <Select.Option key={device.id} value={device.id}>
              {device.name} ({device.location})
            </Select.Option>
          ))}
        </Select>
      </Form.Item>

      <Form.Item
        label="执行间隔"
        name="intervalMinutes"
        rules={[
          { required: true, message: '请输入执行间隔' },
          { type: 'number', min: 1, max: 1440, message: '执行间隔必须在1-1440分钟之间' }
        ]}
      >
        <InputNumber
          min={1}
          max={1440}
          placeholder="请输入执行间隔（分钟）"
          addonAfter="分钟"
          style={{ width: '100%' }}
        />
      </Form.Item>

      <Form.Item
        label="目标状态"
        name="targetStatus"
        valuePropName="checked"
      >
        <Switch checkedChildren="开" unCheckedChildren="关" />
      </Form.Item>

      <Form.Item
        label="是否启用"
        name="status"
        valuePropName="checked"
      >
        <Switch checkedChildren="是" unCheckedChildren="否" />
      </Form.Item>
    </Form>
  );
};

export default TimerForm; 